import json

def convert_message_to_json(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as f:
        lines = [line.strip() for line in f.readlines() if line.strip()]
    
    articles = []
    for i in range(0, len(lines), 3):  # 改为每3行一组，因为每组数据实际占用3行（标题、内容、链接）
        if i + 2 < len(lines):  # 改为检查是否有足够3行数据
            article = {
                "title": lines[i],
                "content": lines[i+1], 
                "link": lines[i+2]
            }
            articles.append(article)
    
    with open(output_file, 'w', encoding='utf-8') as f:
        json.dump(articles, f, ensure_ascii=False, indent=2)

if __name__ == '__main__':
    input_path = r'c:\Users\lenovo\Desktop\html2inline\message.txt'
    output_path = r'c:\Users\lenovo\Desktop\html2inline\output.json'
    convert_message_to_json(input_path, output_path)